home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / whrandom.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  3.5 KB  |  109 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4.  
  5. class whrandom:
  6.     
  7.     def __init__(self, x = 0, y = 0, z = 0):
  8.         self.seed(x, y, z)
  9.  
  10.     
  11.     def seed(self, x = 0, y = 0, z = 0):
  12.         if not None if type(y) == type(y) and type(z) == type(z) else type(z) == type(0):
  13.             raise TypeError, 'seeds must be integers'
  14.         
  15.         if x <= x:
  16.             pass
  17.         elif x < 256:
  18.             if y <= y:
  19.                 pass
  20.             elif y < 256:
  21.                 pass
  22.         if not None if z <= z else z < 256:
  23.             raise ValueError, 'seeds must be in range(0, 256)'
  24.         
  25.         if x == x and y == y:
  26.             pass
  27.         elif y == z:
  28.             import time
  29.             t = long(time.time() * 256)
  30.             t = int(t & 16777215 ^ t >> 24)
  31.             (t, x) = divmod(t, 256)
  32.             (t, y) = divmod(t, 256)
  33.             (t, z) = divmod(t, 256)
  34.         
  35.         if not x:
  36.             pass
  37.         if not y:
  38.             pass
  39.         if not z:
  40.             pass
  41.         self._seed = (1, 1, 1)
  42.  
  43.     
  44.     def random(self):
  45.         (x, y, z) = self._seed
  46.         x = 171 * x % 30269
  47.         y = 172 * y % 30307
  48.         z = 170 * z % 30323
  49.         self._seed = (x, y, z)
  50.         return (x / 30269.0 + y / 30307.0 + z / 30323.0) % 1.0
  51.  
  52.     
  53.     def uniform(self, a, b):
  54.         return a + (b - a) * self.random()
  55.  
  56.     
  57.     def randint(self, a, b):
  58.         return self.randrange(a, b + 1)
  59.  
  60.     
  61.     def choice(self, seq):
  62.         return seq[int(self.random() * len(seq))]
  63.  
  64.     
  65.     def randrange(self, start, stop = None, step = 1, int = int, default = None):
  66.         istart = int(start)
  67.         if istart != start:
  68.             raise ValueError, 'non-integer arg 1 for randrange()'
  69.         
  70.         if stop is default:
  71.             if istart > 0:
  72.                 return int(self.random() * istart)
  73.             
  74.             raise ValueError, 'empty range for randrange()'
  75.         
  76.         istop = int(stop)
  77.         if istop != stop:
  78.             raise ValueError, 'non-integer stop for randrange()'
  79.         
  80.         if step == 1:
  81.             if istart < istop:
  82.                 return istart + int(self.random() * (istop - istart))
  83.             
  84.             raise ValueError, 'empty range for randrange()'
  85.         
  86.         istep = int(step)
  87.         if istep != step:
  88.             raise ValueError, 'non-integer step for randrange()'
  89.         
  90.         if istep > 0:
  91.             n = ((istop - istart) + istep - 1) / istep
  92.         elif istep < 0:
  93.             n = ((istop - istart) + istep + 1) / istep
  94.         else:
  95.             raise ValueError, 'zero step for randrange()'
  96.         if n <= 0:
  97.             raise ValueError, 'empty range for randrange()'
  98.         
  99.         return istart + istep * int(self.random() * n)
  100.  
  101.  
  102. _inst = whrandom()
  103. seed = _inst.seed
  104. random = _inst.random
  105. uniform = _inst.uniform
  106. randint = _inst.randint
  107. choice = _inst.choice
  108. randrange = _inst.randrange
  109.